<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>部门管理</title>
    <link href="../../../static/css/style.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../../static/js/jquery.js"></script>
</head>
<script>
    //数据回显
    $(function () {
        var deptId = JSON.parse(localStorage.getItem("sysdeptId2"));
        $.ajax({
            type: "post",
            url: "/dept/deptDetail",
            data: {deptId: deptId},
            dataType: "JSON",
            success: function (rm) {
                $("#deptId").val(rm.data.deptId);
                $("#deptName").val(rm.data.deptName);
                var pid = rm.data.pid;
                var cid = rm.data.cid;
                //省
                $.ajax({
                    type: "post",
                    url: "/dept/provinceList",
                    data: {},
                    dataType: "JSON",
                    success: function (rm) {
                        var pStr2 = '<option value="">请选择</option>';
                        for (let i = 0; i < rm.data.length; i++) {
                            if (pid == rm.data[i].id) {
                                pStr2 += '<option selected="selected" value="' + rm.data[i].id + '">' + rm.data[i].pname + '</option>';
                            } else {
                                pStr2 += '<option value="' + rm.data[i].id + '">' + rm.data[i].pname + '</option>';
                            }
                        }
                        $("#pId").html(pStr2);
                    },
                    error: function (rm) {
                        alert(rm.msg)
                    }
                });
                //市
                $.ajax({
                    type: "post",
                    url: "/dept/cityList",
                    data: {},
                    dataType: "JSON",
                    success: function (rm) {
                        var cities = rm.data;
                        var cStr2 = '<option value="">请选择</option>';
                        for (let j = 0; j < rm.data.length; j++) {
                            if (cid == cities[j].id) {
                                cStr2 += '<option selected="selected" value="' + cities[j].id + '">' + cities[j].cname + '</option>';
                            } else {
                                cStr2 += '<option value="' + cities[j].id + '">' + cities[j].cname + '</option>';
                            }
                        }
                        $("#cId").html(cStr2);
                    },
                    error: function (rm) {
                        alert(rm.msg)
                    }
                });
            }
        });
    });

    function f() {
        var pId = $("#pId").val();
        // 地区查询
        $.ajax({
            type: "post",
            url: "/dept/cityList",
            data: {pId: pId},
            dataType: "JSON",
            success: function (rm) {
                var cities = rm.data;
                var cStr2 = '<option value="">请选择</option>';
                for (let j = 0; j < rm.data.length; j++) {
                    if (pId != cities[j].pid) {
                        cStr2 += '';
                    } else {
                        cStr2 += '<option value="' + cities[j].id + '">' + cities[j].cname + '</option>\n';
                    }
                    $("#cId").html(cStr2);
                }
            },
            error: function (rm) {
                alert(rm.msg)
            }
        });
    }

    function deptUpdateSave() {
        $.ajax({
            type: "post",
            url: "/dept/deptUpdate",
            data: $("#Form").serializeArray(),
            traditional: true,
            async: true,
            dataType: "JSON",
            success: function () {
                window.location.href = "findByPage";
            },
            error: function (rm) {
                alert(rm.msg);
            }
        });
    }
</script>
<body>
<form id="Form">
    <div class="place"><span>位置：</span>
        <ul class="placeul">
            <li><a href="../dept/findByPage">系统管理</a></li>
            <li><a href="../dept/findByPage">部门管理</a></li>
            <li><a href="../dept/deptUpdate">修改</a></li>
        </ul>
    </div>
    <div class="formbody">
        <div class="formtitle"><span>部门信息</span></div>
        <ul class="forminfo">
            <li>
                <input name="deptId" id="deptId" type="hidden" value="001" class="dfinput" readonly/>
            </li>
            <li>
                <label>部门名称</label>
                <input name="deptName" id="deptName" type="text" value="研发部" class="dfinput"/>
                <i>必填，不能超过30个字符</i>
            </li>
            <li>
                <label>所属区域</label>
                <select class="dfselect" id="pId" name="pId" onchange="f()">
                    <option value="">请选择</option>
                    <option>北京</option>
                    <option selected="selected">江苏</option>
                    <option>天津</option>
                </select>
                省
                <select class="dfselect" id="cId" name="cId">
                    <option value="">请选择</option>
                    <option>北京</option>
                    <option selected="selected">南京</option>
                    <option>天津</option>
                </select>
                市
<!--                <i>必选</i>-->
            </li>

            <li>
                <label>&nbsp;</label>
                <input name="" type="button" class="btn" value="确认保存" onclick="deptUpdateSave()"/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input name="" type="button" class="btn" value="返回" onclick="window.history.go(-1);"/>
            </li>
        </ul>
    </div>
</form>
</body>
